<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
  <!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" /> -->
  <link rel="stylesheet" href="./model.css">
</head>

<body>
  <div id="app">
    <button @click="open">打开提示框</button>
  </div>
  <template id="Promptbox">
    <div class="notice right" v-if="this.show">
      <h3>
        <!-- <slot #title></slot> -->
        {{title}}
      </h3>
      <p>{{message}}</p>
      <div class="ui buttons">
        <button class="button" @click="determine">确定</button>
        <button class="button" @click="cancle">取消</button>
      </div>
    </div>
  </template>
  <script src="https://cdn.bootcss.com/vue/2.5.16/vue.min.js"></script>
  <script>
    let PromptboxOBJ = {
      template: '#Promptbox',
      data() {
        return {
          show: false,
          title: '',
          message: '',
          duration: 1000
        }
      },
      methods: {
        determine() {
          this.show = false
        },
        cancle() {
          this.show = true
        }
      },
      mounted() {
        setTimeout(() => {
          this.show = true
        }, this.duration)
      }
    }
    // Vue.component('Promptbox', PromptboxOBJ)
    const Promptbox = Vue.extend(PromptboxOBJ)
    // 利用这个Promptbox构造函数可以new一个instance 这个上面会有$mount渲染方法,我们只需要appendChlid即可
    function notice(options) {
      const instance = new Promptbox({ data: options })
      instance.$mount()
      document.body.appendChild(instance.$el)
      return instance
    }
    const vm = new Vue({
      el: '#app',
      data: {
        str: 'aaa'
      },
      methods: {
        open() {
          notice({
            title: '提示',
            message: 'nihaoya,this is a test notice',
            duration: 500
          })
        }
      }
    })
  </script>
</body>

</html>